package com.yangjifang.mr.flowsum;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * 简单的类型不能方便的传输复杂的数据 因此需要能序列化的类来携带数据
 */
public class FlowCountMapper extends Mapper<LongWritable, Text,Text,FlowBean> {

    Text k = new Text();
    FlowBean v = new FlowBean();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //7  134212343221   120.196.100.99    1116  954    200
        //获取一行
        String line = value.toString();
        //切割
        String[] fields = line.split("\t");
        //封装对象
        k.set(fields[1]); //手机号

        long upFlow = Long.parseLong(fields[fields.length - 3]);
        long downFlow =  Long.parseLong(fields[fields.length-2]);
        v.setUpFlow(upFlow);
        v.setDownFlow(downFlow);

        //写出
        context.write(k,v);
    }
}
